package com.mm.learn.shopping.order;

import com.mm.learn.shopping.order.service.OrderService;
import com.mm.learn.shopping.order.vo.OrderConfirmVo;
import com.mm.learn.shopping.order.vo.OrderSubmitVo;
import com.mm.learn.shopping.order.vo.SubmitOrderResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @author wdd
 */
@Controller
public class OrderController {


    @Autowired
    OrderService orderService;


    /**
     * 订单确认页面
     *
     * @param model
     * @return
     */
    @GetMapping("/toTrade")
    public String toTrade(Model model) {
        OrderConfirmVo confirmOrder = orderService.confirmOrder();
        model.addAttribute("confirmOrder", confirmOrder);
        return "confirm";
    }

    /**
     * 下单功能
     * @param submitVo
     * @return
     */
    @PostMapping("/submitOrder")
    public String submitOrder(OrderSubmitVo submitVo) {
       SubmitOrderResponseVo vo =  orderService.submitOrder(submitVo);
        //下单成功来到支付选择页
        if (vo.getCode() == 0){

        }else {
            //下单失敗回到订单确认页重新确认订单信息
        }
        System.out.println("订单提交的数据..."+submitVo);
        return null;
    }

}
